import { obtainMusicScore, obtainCollectScore, appendScoreToCollect, removeScoreToCollect } from '../../../config/api'
import * as actionTypes from './actionTypes';

const getMusicScore = (data) => ({
	type: actionTypes.Get_Music_Score,
	data
});
const getScoreCollect = (data) => ({
	type: actionTypes.Get_Score_Collect,
	data
});
const appendScoreCollect = (data) => ({
	type: actionTypes.Add_Score_Collect,
	data
})
const removeScoreCollect = (data, mold) => ({
	type: actionTypes.Sub_Score_Collect,
	data,
	mold
})

// 选择  曲谱导航
export const selectScoreNavigate = (data) => ({
	type: actionTypes.Change_Select_Flag,
	data
});

// 获取 曲谱库 数据
export const acquireMusicScoreData = ( page, open_id, union_id ) => {
	return async (dispatch) => {
		const resultInfo = await obtainMusicScore( page, open_id, union_id )
		if (resultInfo.status === 200) {
			console.log(resultInfo.data, '获取 曲谱库 数据')
			dispatch(getMusicScore(resultInfo.data));
		}
	}
};

// 获取 我的曲谱 数据
export const acquireScoreCollectData = ( page, open_id, union_id ) => {
	return async (dispatch) => {
		const resultInfo = await obtainCollectScore( page, open_id, union_id )
		if (resultInfo.status === 200) {
			console.log(resultInfo.data, '获取 我的曲谱 数据')
			dispatch(getScoreCollect(resultInfo.data));
		}
	}
};

// 收藏 图谱到曲谱库
export const enshrineScoreToLibrary = ( item, index, open_id, union_id ) => {
	return async (dispatch) => {
		const resultInfo = await appendScoreToCollect( item.ID, open_id, union_id )
		console.log(resultInfo, '...resultInfo')
		// if (resultInfo.status === 200) {
			dispatch(appendScoreCollect(index));
		// }
	}
}

// 移除 图谱于曲谱库
export const removalScoreFromLibrary = (item, index, open_id, union_id, mold) => {
	return async (dispatch) => {
		const resultInfo = await removeScoreToCollect( item.ID, open_id, union_id )
		console.log(resultInfo, '...resultInfo')
		// if (resultInfo.status === 200) {
			dispatch(removeScoreCollect(index, mold));
		// }
	}
}

